package com.googlecode.lightest.core

import com.googlecode.lightest.core.tutorial.Tutorial1

class RunnerTest extends RunnerTestCase {

    /**
     * Tests that a run results are updated as each test method is run. The
     * test class itself contains assertions that will cause the assertions
     * in this method to fail, should the methods in the test class fail. Yes,
     * it's a little confusing!
     */
    void testIntermediateReportGeneration() {
        def testClass = ReportGenerationVerifier.class
        def suiteFile = LightestUtils.createSuiteFile([ testClass ])
        
        runnerSupport.runLightest(suiteFile)
        
        def testResult = runnerSupport.findDetailsByTestMethodName('a')

        assertEquals(TEST_PASSED, testResult.'@status')
        
        testResult = runnerSupport.findDetailsByTestMethodName('b')
        
        assertEquals(TEST_FAILED, testResult.'@status')
        
        testResult = runnerSupport.findDetailsByTestMethodName('c')
        
        assertEquals(TEST_PASSED, testResult.'@status')
        
        testResult = runnerSupport.findDetailsByTestMethodName('d')
        
        assertEquals(TEST_PASSED, testResult.'@status')
    }
    
    void testExtraListenerIsRegisteredWithTestNG() {
        def testClass = Tutorial1.class
        def suiteFile = LightestUtils.createSuiteFile([ testClass ])
        def listener = new DummyListener()
        
        assertEquals(false, listener.onStartWasCalled)
        assertEquals(false, listener.onFinishWasCalled)
        
        runnerSupport.testNGListeners << listener
        runnerSupport.runLightest(suiteFile)
        
        assertEquals(true, listener.onStartWasCalled)
        assertEquals(true, listener.onFinishWasCalled)
    }
}